define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var matchId = 0;
    var Controller = {
        index: function () {

            matchId = $('#matchId').val();
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'match/ranks/index' + location.search + '&mid='+matchId,
                    // add_url: 'match/member/add?matchId='+matchId,
                    // edit_url: 'match/member/edit',
                    // del_url: 'match/member/del',
                    // multi_url: 'match/member/multi',
                    // import_url: 'match/member/import',
                    table: 'match_member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),visible:false},
                        {field: 'match_id', title: __('Match_id'),visible:false},
                        {field: 'match.name', title: __('Match.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user_id', title: __('User_id'),visible:false},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'real_name', title: __('Real_name'), operate: 'LIKE'},
                        //{field: 'idcard', title: __('Idcard'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'ranks', title: '排名', operate: false},
                        {field: 'score', title: __('Score'), operate:'BETWEEN'},
                        // {field: 'is_out', title: __('Is_out'), searchList: {"0":__('Is_out 0'),"1":__('Is_out 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'out_round', title: __('Out_round')},
                        // {field: 'out_round_title', title: '出局轮次'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            console.log(matchId);
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
